<template>
  <div>
    <div class="home-header-fixed" v-if="show">
      <el-row class="home-search">
        <Searchbox class="search-box"></Searchbox>
      </el-row>
    </div>
  </div>
</template>

<script>
import Searchbox from '@/components/Searchbox.vue'

export default {
  components: {
    Searchbox
  },
  data () {
    return {
      show: false
    }
  },
  mounted () {
    window.addEventListener('scroll', this.showSearch)
  },
  methods: {
    showSearch () {
      const scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop
      if (scrollTop > 150) {
        this.show = true
      } else {
        this.show = false
      }
    }
  }
}
</script>

<style lang="less" scoped>
.home-header-fixed {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px;
  z-index: 100;
  background-color: #f5f5f5;
  box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.2);
  .search-box {
    margin: 0 auto;
  }
}
</style>
